from manim import *

class AddSquares(Scene):

    # 写一个方法，该方法可以向NumberPlane中添加n个单位长度的正方形，沿着x方向排
    def add_squares_to_plane(self, plane, n, square_size=1, square_color=WHITE):
        existing_squares = [mob for mob in plane if isinstance(mob, Square)]
        for i in range(n):
            # 正方形不透明
            square = Square(side_length=square_size, color=square_color,fill_opacity=1).move_to((len(existing_squares) + i+0.5, 0.5, 0))
            plane.add(square)
    def construct(self):

        number_plane = NumberPlane()
        self.add_squares_to_plane(number_plane, 3,square_color=GREEN)
        self.add_squares_to_plane(number_plane, 2,square_color=RED)
        self.add_squares_to_plane(number_plane, 1,square_color=BLUE)
        self.add(number_plane)

